package com.itheima.device.dao;

import com.itheima.device.pojo.DeviceIndex;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestBody;
import tk.mybatis.mapper.common.Mapper;

@Repository
public interface DeviceIndexMapper extends Mapper<DeviceIndex> {



   //根据设备id删除设备与设备指标
    @Delete("DELETE t_device,t_index FROM t_device LEFT JOIN t_index ON t_device.id = t_index.id WHERE t_device.id = #{id}")
    void deleteIndexById(Integer id);



    //根据设备id删除设备与设备指标的关联关系
    @Delete("Delete t_device_index from t_device_index where t_device_index.did=#{id}")
    void deleteDeviceAndDeviceIndexRel(Integer id);

    //中间表加入数据
    @Insert("INSERT INTO `t_device_index`(`did`, `iid`) VALUES (#{did}, #{iid})")
    void inserToDeviceIndex(@Param("did") Integer did,@Param("iid")Integer iid);
    //根据设备id查询指标id
    @Select("select iid from t_device_index where id=#{id}")
    Integer findIidByDeviceId(Integer id);

}
